<?php //pack11class

class ObjectsListItemBodyText extends ObjectsListItem {

    public $traceEnabled=true;
    const COUNT=300;

    public $more="";

    protected $object;

	public function setup() {
        $object=$this->object=$this->parent->getObject();

        $settingObject=SettingsManager::getSetting("object");
        $setting=clone $settingObject;
        $setting->value=$object->id;
        $queryObject=new GetQueryObject;
        $queryObject->setValue($setting, GetQueryObject::SETTING);

        $currencyObject=SettingsManager::getSetting("currency");
        //trace("LIST CURRENCY: ".$currencyObject->value);
        $queryObject->setValue($currencyObject, GetQueryObject::SETTING);

        $query=GetQuery::generate($queryObject);

        $moreItem=new ObjectsListItemBodyMore;
        $moreItem->link="?state=".$query;
        $this->more=Template::html($moreItem);

        /*$properties=$object->usedProperties();
        $strArray=array();
        foreach($properties as $property){
            if(!$property->setting) array_push($strArray,$property->string);
        }
        $finalString=implode(", ",$strArray);*/
            mb_internal_encoding('utf-8');
        $finalString=str_replace(array("\r\n", "\r", "\n"), ' ', strip_tags(html_entity_decode($object->description[LanguagesManager::current()])));
        if(mb_strlen($finalString)==0) {
            foreach(LanguagesManager::getLanguages() as $language) {
                $finalString=str_replace(array("\r\n", "\r", "\n"), ' ', $object->description[$language->id]);
                if(mb_strlen($finalString,'utf-8')>0) break;
            }
            if(mb_strlen($finalString)==0) $finalString="Value not set";
        }
        if(mb_strlen($finalString)<=self::COUNT) {
            $this->setBody($finalString." ");
        } else {
            $hiddenString=mb_substr($finalString,self::COUNT,mb_strlen($finalString));
            $space=mb_strpos($hiddenString," ");
            if(!is_numeric($space)) {
                $this->setBody($finalString." ");
            } else {
                $this->setBody(mb_substr($finalString,0,(self::COUNT+$space))."...");
            }
        }
        
    }

}
?>
